<template>
  <Layout class="p-5 bg-white">
    <Form :label-width="80" class="p-5">
      <Row>
        <Col span="9" push="5">
          <FormItem class="w-100" label="学生姓名">
            <label>{{ studentName }}</label>
          </FormItem>

          <FormItem class="w-100" label="回访人">
            <label>{{ backview.autorNickName }}</label>
          </FormItem>

          <FormItem class="w-100" label="回访方式">
            <i-col>
              <Select
                v-model="backview.method"
                placeholder="请输入回访方式"
                filterable
                clearable
              >
                <Option v-for="item in backviewList" :value="item.value"
                  >{{ item.label }}
                </Option>
              </Select>
            </i-col>
          </FormItem>

          <FormItem class="w-100" label="回访类型">
            <Input
              v-model="backview.type"
              placeholder="未开放"
              disabled
            ></Input>
          </FormItem>

          <FormItem label="回访日期">
            <Date-picker
              class="w-100"
              type="datetime"
              :value="this.formatDate(new Date()) + ' 00:00:00'"
              placeholder="回访日期"
              @on-change="dataChange"
            ></Date-picker>
          </FormItem>

          <FormItem class="w-100" label="回访描述">
            <Input
              type="textarea"
              v-model="backview.des"
              :autosize="{ minRows: 4, maxRows: 8 }"
              placeholder="请输入回访描述"
            ></Input>
          </FormItem>

          <FormItem class="w-100" label="回访结果">
            <Input
              disabled
              type="textarea"
              v-model="backview.result"
              :autosize="{ minRows: 3, maxRows: 5 }"
              placeholder="未开放"
            ></Input>
          </FormItem>
          <FormItem class="text-right">
            <Button @click="submit" type="primary">提交</Button>
            <Button @click="cancel" class="ml-2">取消</Button>
          </FormItem>
        </Col>
      </Row>
    </Form>
    <Loadding v-bind:loadinghuan="isSpinShow"></Loadding>
  </Layout>
</template>

<script>
export default {
  data() {
    return {
      isSpinShow: false,
      backview: {
        //新增的信息对应的文本框信息
        id: null,
        type: '',
        autorNickName: null,
        des: '',
        result: '',
        dateTime: '',
        stage: null,
        method: '',
        cu: null,
        ct: '',
        uu: null,
        ut: '',
        insertBackviewTime: this.formatDate(new Date()) + ' 00:00:00',
      },
      studentName: '',
      backviewList: [
        { value: '电话回访', label: '电话回访' },
        { value: 'QQ回访', label: 'QQ回访' },
        { value: '微信回访', label: '微信回访' },
        { value: '邮件回访', label: '邮件回访' },
        { value: '其他', label: '其他' },
      ],
    }
  },
  methods: {
    dataChange: function(datetime) {
      this.backview.insertBackviewTime = datetime
    },
    changeP: function(selectedPermissionId) {},
    submit: function() {
      let _this = this

      if (this.$data.backview.des === '') {
        this.message.error('请输入回访描述')
        return
      }

      if (this.$data.backview.autor === null) {
        this.message.error('请输入回访人')
        return
      }

      if (this.$data.backview.insertBackviewTime === '') {
        this.message.error('请输入回访日期')
        return
      }

      /* if (this.$data.backview.result === '') {
        this.message.error('请输入回访结果')
        return
      } */

      // if (this.$data.backview.type === '') {
      //   this.message.error('请输入回访类型')
      //   return
      // }

      var backview = {
        studentId: this.$route.params.row.studentId,
        type: _this.backview.type,
        autor: this.$route.params.row.autorId,
        des: _this.backview.des,
        result: _this.backview.result,
        dateTime: this.backview.insertBackviewTime,
        method: _this.backview.method,
        sourceId: 1,
        stageId: this.$route.params.stageId,
        cu: this.backview.cu,
      }
      this.isSpinShow = true
      this.http
        .post({
          url: '/backview',
          param: backview,
        })
        .then((data) => {
          this.isSpinShow = false
          _this.message.info('添加成功')
          if (this.$route.params.stageId === 1) {
            this.$tabs.close({ to: '/resource' })
          }

          if (this.$route.params.stageId === 2) {
            this.$tabs.close({ to: '/interview' })
          }

          if (this.$route.params.stageId === 3) {
            this.$tabs.close({ to: '/try' })
          }
        })
    },
    cancel: function() {
      if (this.$route.params.stageId === 1) {
        this.$tabs.close({ to: '/resource' })
      }

      if (this.$route.params.stageId === 2) {
        this.$tabs.close({ to: '/interview' })
      }

      if (this.$route.params.stageId === 3) {
        this.$tabs.close({ to: '/try' })
      }
    },
    init: function() {},
    formatDate: function(date) {
      //格式化日期方法! ----> yyyy-MM-dd
      var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear()

      if (month.length < 2) month = '0' + month
      if (day.length < 2) day = '0' + day
      return [year, month, day].join('-')
    },
  },
  destroyed: function() {
    //跳转页面!
    if (this.$route.params.stageId === 1) {
      this.$router.push({
        name: 'resource',
      })
    }

    if (this.$route.params.stageId === 2) {
      this.$router.push({
        name: 'interview',
      })
    }

    if (this.$route.params.stageId === 3) {
      this.$router.push({
        name: 'try',
      })
    }
  },
  created: function() {
    this.init()
    this.studentName = this.$route.params.row.name
    this.backview.autorNickName = this.$route.params.row.autor
    let currentUser = JSON.parse(sessionStorage.getItem('CURRENT_USER'))
    this.backview.cu = currentUser.user.userId
  },
}
// 25行  v-model="backview.insertBackviewTime"
</script>

<style></style>
